package com.ukao.pad.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.pad.R;
import com.ukao.pad.bean.BatchlTabBean;
import com.ukao.pad.listener.OnItemChildClickListener;
import com.ukao.pad.utils.CheckUtils;
import com.ukao.pad.widget.StateButton;

import java.util.List;


/**
 * Created by ukaodev on 2017/6/14.
 * 工厂list
 */

public class FactoryListAdapter extends CommonAdapter<BatchlTabBean.ListBean> {



    public FactoryListAdapter(Context context, List<BatchlTabBean.ListBean> datas) {
        super(context, datas, R.layout.adapter_factory_fist);

    }
    private OnItemChildClickListener mOnItemChildClickListener;
    public  void  setOnItemChildClickListener(OnItemChildClickListener mOnItemChildClickListener){
        this.mOnItemChildClickListener=mOnItemChildClickListener;
    }



    @Override
    public void convert(final ViewHolder holder, BatchlTabBean.ListBean item) {


        TextView code=holder.getView(R.id.code);
        TextView    storeName=holder.getView(R.id.storeName);
        TextView    factoryName=holder.getView(R.id.factoryName);
        TextView    statusText=holder.getView(R.id.statusText);
        TextView    productCnt=holder.getView(R.id.productCnt);
        TextView    logisticsWorkName=holder.getView(R.id.logisticsWorkName);
        StateButton isFinish=holder.getView(R.id.isFinish);
        StateButton    deleteBtn=holder.getView(R.id.delete_btn);
        StateButton    printBtn=holder.getView(R.id.print_receipt_btn);
        StateButton    easyPrintBtn=holder.getView(R.id.easy_print_btn);

        code.setText(item.getCode());
        storeName.setText(CheckUtils.isEmptyString(item.getStoreName()));
        factoryName.setText(CheckUtils.isEmptyString(item.getFactoryName()));
        statusText.setText(CheckUtils.isEmptyString(item.getStatusText()));
        productCnt.setText("衣物"+item.getProductCnt()+"件,"+"附件"+item.getAnnexCnt()+"件");
        logisticsWorkName.setText("物流人员："+CheckUtils.isEmptyString(item.getLogisticsWorkName())+CheckUtils.isEmptyString(item.getLogisticsWorkPhone()));
        View.OnClickListener  OnClickListener= new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!CheckUtils.isNull(mOnItemChildClickListener))
                    mOnItemChildClickListener.onChildItemClick(v.getId(), getPosition(holder));
            }
        };
        if (item.getIsFinish()){
            easyPrintBtn.setVisibility(View.VISIBLE);
            printBtn.setVisibility(View.VISIBLE);
            isFinish.setVisibility(View.GONE);
            deleteBtn.setVisibility(View.GONE);

        }else{
            easyPrintBtn.setVisibility(View.GONE);
            printBtn.setVisibility(View.GONE);
            if (item.getProductCnt()==0){
                isFinish.setVisibility(View.GONE);
            }else{
                isFinish.setVisibility(View.VISIBLE);
            }
            deleteBtn.setVisibility(View.VISIBLE);
        }
        printBtn.setOnClickListener(OnClickListener);
        isFinish.setOnClickListener(OnClickListener);
        deleteBtn.setOnClickListener(OnClickListener);
        easyPrintBtn.setOnClickListener(OnClickListener);




    }





}
